/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package locusts.lib.geom;

import java.awt.Rectangle;
import java.awt.Shape;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.PathIterator;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;

/**
 *
 * @author hamish
 */
public class ArrowBox implements Shape, Cloneable {

    private final GeneralPath path;

    public ArrowBox(double x, double y, double w, double h) {
        path = createArrowBox(x, y, w, h);
    }

    public ArrowBox(double x, double y, double size) {
        this(x,y,size,size);
    }

    protected ArrowBox(ArrowBox that) {
        this.path = (GeneralPath) that.path.clone();
    }
    
    private static GeneralPath createArrowBox(double x, double y, double w,
            double h) {

        final double x1 = (x);
        final double x2 = (x + w * .25);
        final double x3 = (x + w * .40);
        final double x4 = (x + w * .5);
        final double x5 = (x + w * .6);
        final double x6 = (x + w * .75);
        final double x7 = (x + w);

        final double y1 = (y);
        final double y2 = (y + h * .5);
        final double y3 = (y + h * .75);
        final double y4 = (y + h);

        final GeneralPath shape = new GeneralPath(GeneralPath.WIND_NON_ZERO,
                12);

        shape.moveTo((float) x1, (float) y1);
        shape.lineTo((float) x1, (float) y2);
        shape.lineTo((float) x3, (float) y2);
        shape.lineTo((float) x3, (float) y3);
        shape.lineTo((float) x2, (float) y3);
        shape.lineTo((float) x4, (float) y4);
        shape.lineTo((float) x6, (float) y3);
        shape.lineTo((float) x5, (float) y3);
        shape.lineTo((float) x5, (float) y2);
        shape.lineTo((float) x7, (float) y2);
        shape.lineTo((float) x7, (float) y1);
        shape.closePath();

        return shape;
    }


    public Rectangle getBounds() {
        return path.getBounds();
    }

    public Rectangle2D getBounds2D() {
        return path.getBounds2D();
    }

    public boolean contains(double x, double y) {
        return path.contains(x, y);
    }

    public boolean contains(Point2D p) {
        return path.contains(p);
    }

    public boolean intersects(double x, double y, double w, double h) {
        return path.intersects(x, y, w, h);
    }

    public boolean intersects(Rectangle2D r) {
        return path.intersects(r);
    }

    public boolean contains(double x, double y, double w, double h) {
        return path.contains(x, y, w, h);
    }

    public boolean contains(Rectangle2D r) {
        return path.contains(r);
    }

    public PathIterator getPathIterator(AffineTransform at) {
        return path.getPathIterator(at);
    }

    public PathIterator getPathIterator(AffineTransform at, double flatness) {
        return path.getPathIterator(at, flatness);
    }

    @Override
    public ArrowBox clone() {
        return new ArrowBox(this);
    }
}
